import Mine from "../facility/pulbicFacility/Mine";
import Dialog from "./Dialog";

const { ccclass, property } = cc._decorator;

/**
 * 升级弹窗
 */
@ccclass
export default class MineDialog extends Dialog {
    mine: Mine;

    protected onDisable(): void {
        this.mine?.node.targetOff(this);
    }

    public init(facility: Mine) {
        this.mine = facility;
        this.mine.node.on(Mine.EventType.LoseMine, this.reset, this);
        this.reset()
    }


    reset() {
        let progrss = this.getComponentInChildren(cc.ProgressBar);
        progrss.progress = this.mine.curCount / this.mine.maxCount;
        this.node.getChildByName("balance").getComponent(cc.Label).string = `${this.mine.curCount}/${this.mine.maxCount}`
    }
}
